const imgUrl = 'https://mystore-1304299581.cos.ap-guangzhou.myqcloud.com/static/image/'
const img_url = 'http://192.168.100.180:8364'
import tools from '@/common/utils/tools.js'
import api from '@/common/request/index.js'
const state = {
	gameList: [],   // 游戏列表
	aa: 1,
	prizeName: null,
	priseRes: null,
	prizeList: [],  // 奖品数据
    key: null,      // 游戏key值
    pageDraw: [],   // 抽奖记录
}

const mutations = {
	//获取
	set_gameList(state,payload) {
		state.gameList = payload.gamePrize
	},
	set_gameDetail(state,payload) {
		state.priseRes = payload
		state.prizeList = payload.gamePrize	
	},
	set_prise(state,payload) {
		state.prizeName = payload
	},
    set_key(state, payload) {
        state.key = payload
    }
}

const actions = {
    // 修改key值
    get_key({commit}, payload) {
        commit('set_key', payload);
    },
	//获取游戏列表
	get_gameList({commit},payload) {
		return new Promise((resolve,reject) => {
			let obj = {
				key: payload
			}
			api('game.list',obj).then(res => {
				commit ('set_gameList', res.data)
                resolve(res)
			}).catch(e => {
				reject(e)
			})
		})
	},
	//获取游戏详情
	get_gameDetail({commit},payload) {
		return new Promise((resolve,reject) => {
			let obj = {
				key: payload
			}
			api('game.detail',obj).then(res => {
				commit ('set_gameDetail', res.data)
                resolve(res)
			}).catch(e => {
				reject(e)
			})
		})
	},
	get_prise({commit,state}, payload) {
		return new Promise((resolve,reject) => {
			api('game.luckdraw', payload).then(res => {
				commit('set_prise',res.data)
                resolve(res)
			}).catch(e => {
                reject(e)
            })
		})
	},
    get_pageDraw({commit, state}, payload) {
        return new Promise((resolve, reject) => {
            api('game.pageDraw', payload).then(res => {
                if (res.status === 1) {
                    res.data.data.forEach((item, index) => {
                        let draw_time = tools.time_data(item.draw_time, 'b_date');
                        item.draw_time = draw_time;
                    })
                    state.pageDraw = res.data;
                    resolve(res.data.data)
                }
            })
        })
    }
}


export default {
	namespaced: true,
	state,
	mutations,
	actions
}